//
define('wangwu/ceshi/AppMap',
    [
        'dojo/_base/declare',
        'dojo/_base/lang',
        'dojo/on',
        'dojo/_base/connect',


        'esri/Evented',
        'esri/map',
        'esri/geometry/Point',
        'esri/SpatialReference',

        'esri/layers/ArcGISDynamicMapServiceLayer',
        'esri/layers/ArcGISTiledMapServiceLayer',
        'keepsoft/gis/extlayers/GoogleTiledMapServiceLayer',
        'keepsoft/gis/extlayers/TdtTiledMapServiceLayer'

    ],
    function(declare, lang, on, connect,
             Evented, Map,Point,SpatialReference,
             ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer
             ){
        var d = declare([Evented], {
            _eventMap:{
                'map-did-load':!0
            },
            constructor:function(divid, mapo, o){
                this.mapDivId = divid;

                this.mapOption = mapo;
                var lods=[
                    //{"level" : 0, "resolution" : 2445.98490512499, "scale" : 9244648.868618},
                    //{"level" : 1, "resolution" : 1222.99245256249, "scale" : 4622324.434309},
                    //{"level" : 2, "resolution" : 611.49622628138, "scale" : 2311162.217155},
                    //{"level" : 3, "resolution" : 305.748113140558, "scale" : 1155581.108577},
                    //{"level" : 4, "resolution" : 152.874056570411, "scale" : 577790.554289},
                    //{"level" : 5, "resolution" : 76.4370282850732, "scale" : 288895.277144},
                    //{"level" : 6, "resolution" : 38.2185141425366, "scale" : 144447.638572},
                    //{"level" : 7, "resolution" : 19.1092570712683, "scale" : 72223.819286},
                    //{"level" : 8, "resolution" : 9.55462853563415, "scale" : 36111.909643},
                    //{"level" : 9, "resolution" : 4.77731426794937, "scale" : 18055.954822},
                    //{"level" : 10, "resolution" : 2.38865713397468, "scale" : 9027.977411},
                    //{"level" : 11, "resolution" : 1.19432856685505, "scale" : 4513.988705},
                    //{"level" : 12, "resolution" : 0.597164283559817, "scale" : 2256.994353},
                    //{"level" : 13, "resolution" : 0.298582141647617, "scale" : 1128.497176}
                ];


                this.map = new Map(this.mapDivId, this.mapOption || {
                        //lods:lods
                    });

                this.option = {

                };

                (o)?lang.mixin(this.option, o):0;

            },
            //----------------------------------------------public-----------------------------------------------
            init:function(){
                //坐标
                this.map.centerAndZoom(new Point(112.13,35.27, new SpatialReference({wkid:4326})), 5);
                this._init();

            },

            //---------------------------------------------private----------------------------------------------
            _init:function(){
                //添加事件侦听
                on(this.map, "load", lang.hitch(this, this._baseLayerLoaded));
                this._addLayers();
            },
            _addLayers:function(){
                console.log('addLayer...');
                //var WorldImageryUrl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer";
                //var WorldImager = new ArcGISTiledMapServiceLayer(WorldImageryUrl);
                //WorldImager.id = 'WorldImagerLayer';
                //WorldImager.name = "世界地图";
                //this.map.addLayer(WorldImager);
                var chinaMapUrl = "http://localhost:6080/arcgis/rest/services/china/chinaMap_web/MapServer";
                var chinaMap = new ArcGISTiledMapServiceLayer(chinaMapUrl);
                chinaMap.id = 'chinaMapLayer';
                chinaMap.name = "中国地图";
                this.map.addLayer(chinaMap);
            },
            _baseLayerLoaded:function(){
                console.log('baseLayerLoaded...');
                this._loadMapModule();

            },
            _loadMapModule:function(){
                console.log('loadMapModule...');
                //this.mouseTip = new MouseTip(this.map,{string:"点击选择管线"});
                //this.test = new test(this.map);
                //this.d3Test.init();
                this.onMapDidLoad();
            },

            //--------------------------------------------pre event--------------------------------------------------

            //---------------------------------------------event----------------------------------------------------
            onMapDidLoad:function(){
                console.log('onMapDidLoad...');
            }
        });

        return d;
    });